//var ydcbdb_jgid;
$(function () {
    //======================
    //======设置查询条件========
    //======================
    //判断查询范围，如果查询范围不是全部不允许更改机构
    /* if ($("#ydcbdb_cxfw").val() != 0) {
        ydcbdb_jgid = $("#ydcbdb_jg").val();
        $("#ydcbdb_gsId").val($("#ydcbdb_jgmc").val());
        $("#ydcbdb_gsId").attr("readonly", true);
    } else {
        $("#ydcbdb_gsId").jygsjgcombotree();
        // $("#ydcbdb_gsId").jygsjgcombotree();
    }*/
    $("#ydcbdb_gsId").jygsjgwqxcombotree();
    //======================移动成本对比导出==========================
    $("#ydcbdb_toolbar [name='ydcbdb_dc']").click(function(){
        /* var gsid;
       if ($("#ydcbdb_cxfw").val() != 0) {
            gsid = ydcbdb_jgid;
        } else {
            gsid = $("#ydcbdb_gsId").combotree("getValue");
        }*/
       // gsid = $("#ydcbdb_gsId").combotree("getValue");
        window.open($.webPath() +encodeURI(encodeURI( "/tjbb/ydcbdb/exportydcbdb?begindt=" + $("#ydcbdb_start").datebox("getValue") +
            "&enddt=" +$("#ydcbdb_end").datebox("getValue") +
            "&gsid=" +$("#ydcbdb_gsId").combotree("getValue")+
            "&custname=" + $("#ydcbdb_toolbar [name='ydcbdb_gys']").val() +
            "&jylb=" + $("#ydcbdb_toolbar [name='ydcbdb_jylb']").val() +
            "&xslx=" + $("#ydcbdb_toolbar [name='ydcbdb_xslx']").val())));
    });

    //==============================移动对比搜索按钮========================================
    $("#ydcbdb_toolbar [name='searchButton']").click(function () {
        ydcbdb_search();
    });
    function ydcbdb_search() {
       // var gsid;
       /* if ($("#ydcbdb_cxfw").val() != 0) {
            gsid = ydcbdb_jgid;
        } else {
            gsid = $("#ydcbdb_gsId").combotree("getValue");
        }*/
        //gsid = $("#ydcbdb_gsId").combotree("getValue");
        $(grid).datagrid({
            queryParams: {
                //  gsid: $("#ydcbdb_toolbar [name='ydcbdb_gsId']").val(),
                gsid: $("#ydcbdb_gsId").combotree("getValue"),
                custname: $("#ydcbdb_toolbar [name='ydcbdb_gys']").val(),
                begindt: $("#ydcbdb_toolbar [name='ydcbdb_start']").val(),
                enddt: $("#ydcbdb_toolbar [name='ydcbdb_end']").val(),
                jylb: $("#ydcbdb_toolbar [name='ydcbdb_jylb']").val(),
                xslx: $("#ydcbdb_toolbar [name='ydcbdb_xslx']").val()

            }});
    };

//======================
//========统计列表========   columns        frozenColumns
//======================
    var frozenColumns = [
        [
            {field: 'gs_name', title: '销售公司',  width: 84,align:'center'},
            {field: 'bm_name', title: '销售部门',width: 106,align:'center'},
            {field: 'xsdh', title: '销售单号', width: 155,align:'center'}]]
    var columns= [
        [
            {field: 'ckrq', title: '出库日期', width: 79,align:'center'},
            {field: 'cust_name', title: '客户名称', width: 173,align:'center'},
            {field: 'pm', title: '品名', width: 82,align:'center'},
            {field: 'ggxh', title: '规格型号', width: 90,align:'center'},

             {field: 'th', title: '图号', width: 34,align:'center'},
            {field: 'dw', title: '单位', width: 34,align:'center'},
            {field: 'cd', title: '产地', width: 50,align:'center'},
            {field: 'xssl', title: '销售数量', formatter: function (value) {
                var sl = formatSl(value, ",");
                return sl;
            }, width: 112,align:'right'},
            {field: 'xsj', title: '销售价', formatter: function (value) {
                var sl = formatSl(value, ",");
                return sl;
            },  width: 100,align:'right'},
            {field: 'xse', title: '销售额', formatter: function (value) {
                var sl = formatSl(value, ",");
                return sl;
            },  width: 129,align:'right'},
            {field: 'xscb', title: '销售成本',  formatter: function (value) {
                var sl = formatSl(value, ",");
                return sl;
            }, width: 129,align:'right'},
            {field: 'xslr', title: '销售利润', formatter: function (value) {
                var sl = formatSl(value, ",");
                return sl;
            },  width: 120,align:'right'},
            {field: 'ydcb', title: '移动成本', formatter: function (value) {
                var sl = formatSl(value, ",");
                return sl;
            },  width: 111,align:'right'},
            {field: 'ydlr', title: '移动利润', formatter: function (value) {
                var sl = formatSl(value, ",");
                return sl;
            },  width: 104,align:'right'}
        ]
    ];
    /*var gsid;
   if ($("#ydcbdb_cxfw").val() != 0) {
        gsid = ydcbdb_jgid;
    } else {
        gsid = $("#ydcbdb_gsId").combotree("getValue");
    }*/
    //gsid = $("#ydcbdb_gsId").combotree("getValue");
    var grid = $('#ydcbdb_grid').datagrid({
        url: $.webPath() + '/tjbb/ydcbdb/ydcbdbList',
        toolbar: "#ydcbdb_toolbar",
        striped:true,
        pagination: true,
        pageSize: 100,
        rownumbers: true,
        singleSelect: true,
        collapsible: true,
        fit: true,
        pageNumber: 1,
        fitColumns: false,
        collapsible:true,
        showFooter: true,
    /*  queryParams: {
          gsid: $("#ydcbdb_gsId").combotree("getValue"),
          custname: $("#ydcbdb_toolbar [name='ydcbdb_gys']").val(),
          begindt: $("#ydcbdb_toolbar [name='ydcbdb_start']").val(),
          enddt: $("#ydcbdb_toolbar [name='ydcbdb_end']").val(),
          jylb: $("#ydcbdb_toolbar [name='ydcbdb_jylb']").val(),
          xslx: $("#ydcbdb_toolbar [name='ydcbdb_xslx']").val()
        },*/
        onLoadSuccess: function () {
            $(".datagrid-htable .datagrid-cell").css('text-align', 'center');
        },
        frozenColumns: frozenColumns ,
        columns:columns
    });
});
